package classloader;

import servlet.HttpServlet;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;

/**
 * @author lbq
 * @version 1.0
 * @date 2021/1/22 22:57
 */
public class WebAppClassLoader {

    public HttpServlet loadClass(File file, String className) {
        try {
            URL url = file.toURL();
            URL[] urls = new URL[]{url};
            ClassLoader cl = new URLClassLoader(urls);
            Class<?> cls = cl.loadClass(className);
            return (HttpServlet) cls.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
